$(document).ready(function() {
	$(window).load(function() {
		var itemId = $("#itemId").attr("value");
		var tagId = $("#tagId").attr("value");
		$("#listcomment").load("./asynGetComment.htm?itemId=" + itemId);
		$("#sametagsmall").load("./asynGetItemsToSmall.htm?tagId=" + tagId);
		$("#samesrcsmall").load("./asynGetItemsToSmallV2.htm?sourceId=100");
	});
	$(window).resize( function (){
		var pos = $("#takenup").position();
		$("#rightboard .side").css({"left":pos.left+"px"});
	});
	$("#commentup").click(function() {
		htmlobj = $.ajax({
			url: "./asynGetLoginInfo.htm",
			async: false
		});
		var isLogin = htmlobj.responseText;
		if (isLogin == "true") {
			var itemId = $("#itemId").attr("value");
			var content = $("#comconstent").attr("value");

			var newcontert = trimStr(content);

			if (newcontert.length > 20) {
				alert("不好意思，您的评论太长了！");
				return;
			}
			if (newcontert.length < 2) {
				alert("不好意思，您的评论太短了！多说点吧！");
				return;
			}

			$("#comconstent").attr("value", "");

			$.get(
				"./asynPubComment.htm",
				{content:newcontert,itemId:itemId},
				function(data){
					$("#listcomment").html(data);
			});
		}
		else {
			var itemId = $("#itemId").attr("value");
			var tagId = $("#tagId").attr("value");
			self.location = "./login.html?redirectUrl=./detail.htm?itemId=" + itemId;
		}

	});
	$("#iamhere").click(function() {
		htmlobj = $.ajax({
			url: "./asynGetLoginInfo.htm",
			async: false
		});
		var isLogin = htmlobj.responseText;
		if (isLogin == "true") {
			alert("赠送您100个圈积分！");
		}
		else {
			alert("请您先登录！");
		}
	});
	//zoom piture;
	$('#zoomr_show').click(function() {
		hidenscroll();
		$.openDOMWindow({
			loader: 1,
			loaderImagePath: 'animationProcessing.gif',
			loaderHeight: 16,
			loaderWidth: 17,
			width: 600,
			windowSourceID: '#realitempic'
		});

		return false;
	});
	$('#mark_image').mouseover(function() {	$("#zoomr_show").css("display","block");	});
	$('#mark_image').mouseout(function() { $("#zoomr_show").css("display","none"); });
	adjustBoard();
});

function textup() {
	var s = document.getElementById('comconstent').value;
	//判断ID为text的文本区域字数是否超过140个
	if (s.length > 10) {
		document.getElementById('comconstent').value = s.substring(0, 10);
	}
}

function trimStr(str) {
	var re = /\s*(\S[^\0]*\S)\s*/;
	re.exec(str);
	return RegExp.$1;
}

function hidenscroll() {
	document.getElementsByTagName('body')[0].style.overflow = 'hidden';
	document.getElementsByTagName('body')[0].scroll = "no";
}

function showscroll() {
	document.getElementsByTagName('body')[0].style.overflow = 'auto';
	document.getElementsByTagName('body')[0].scroll = "yes";
}

function adjustBoard() {
	var pos = $("#takenup").position();
	$("#rightboard .side").css({"top":pos.top+"px","left":pos.left+"px"});
}